//
//  UIWindow+Extension.m
//  CreditManger
//
//  Created by chaiyanan on 15/11/10.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "UIWindow+Extension.h"
#import "HBNavigationController.h"
#import "HBLoginManager.h"
#import "HBTabBarViewController.h"
#import "HBIndexCtrl.h"
#import "HBIntroductionViewController.h"
#import "HBLoginCtrl.h"
#import "HBRegisterCtrl.h"

//#import "HBFindPwdFirstCtrl.h"

@implementation UIWindow (Extension)

- (void)switchRootViewController
{
    [self changeRootCtrlWithUser];
}
/**
 *  根据用户的登陆状态 决定选择哪一个页面
 */
-(void)changeRootCtrlWithUser
{
    [HBLoginManager getCurrentUserFromUserdefault];
    
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"IsNotFirstLaunch"])
    {
        NSArray *coverImageNames = @[@"word_1", @"word_2", @"word_3",@"word_4"];
        NSArray *backgroundImageNames = @[@"lead_1", @"lead_2", @"lead_3",@"lead_4"];
        
        HBIntroductionViewController * introductionView = [[HBIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
        self.rootViewController = introductionView;
//        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"IsNotFirstLaunch"];
//        [[NSUserDefaults standardUserDefaults]synchronize];
        
        introductionView.ActionPreviewClickToSelelct = ^(UIButton *btn){
            [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"IsNotFirstLaunch"];
            [[NSUserDefaults standardUserDefaults]synchronize];
            switch (btn.tag) {
                case 1001:
                {
//                    NSLog(@"asd");
                    HBLoginCtrl *loginCtrl = [[HBLoginCtrl alloc]init];
                    HBNavigationController *nav = [[HBNavigationController alloc] initWithRootViewController:loginCtrl];
                    HBAppDelegate.window.rootViewController = nav;
                    break;
                }
                case 1002:
                {
//                    NSLog(@"qwe");
                    HBRegisterCtrl *loginCtrl = [[HBRegisterCtrl alloc]init];
                    loginCtrl.viewJumping = isFromLinkPage;
                    HBNavigationController *nav = [[HBNavigationController alloc] initWithRootViewController:loginCtrl];
                    HBAppDelegate.window.rootViewController = nav;
                    break;
                }
                case 1003:
                {
//                    NSLog(@"ljk");
                    HBTabBarViewController *tab = [[HBTabBarViewController alloc]init];
                    HBAppDelegate.window.rootViewController = tab;
                    break;
                }
                default:
                    break;
            }
        };
        
//            __weak AppDelegate *weakSelf = self;
//            self.introductionView.didSelectedEnter = ^() {
//                weakSelf.introductionView = nil;
//            };
    }
    else
    {
        HBTabBarViewController *tab = [[HBTabBarViewController alloc]init];
        self.rootViewController = tab;
    }
    
    
    
//    if ([HBLoginManager sharedHBLoginManager].hasLogined)
//    {
////        HBHomeCtrl *home = [[HBHomeCtrl alloc]init];
////        self.rootViewController = [[HBNavigationController alloc]initWithRootViewController:home];
//        
//        HBTabBarViewController *tab = [[HBTabBarViewController alloc]init];
//        self.rootViewController = tab;
//    }
//    else
//    {
//        HBIndexCtrl *login = [[HBIndexCtrl alloc]init];
////        HBLoginCtrl *login = [[HBLoginCtrl alloc]init];
//        HBNavigationController *nav = [[HBNavigationController alloc]initWithRootViewController:login];
//        [nav setNavigationBarHidden:YES];
//        self.rootViewController = nav;
//    }
    
}

@end
